package com.online.teaching.module.admin.course.controller;

import com.github.pagehelper.PageInfo;
import com.online.teaching.module.admin.course.domain.dto.CourseAddDTO;
import com.online.teaching.module.admin.course.domain.dto.TakesAddDTO;
import com.online.teaching.module.admin.course.domain.dto.TeachesAddDTO;
import com.online.teaching.module.admin.course.domain.vo.TeachesGetVO;
import com.online.teaching.module.admin.course.service.AdminCourseService;
import com.online.teaching.module.admin.user.domian.dto.TeacherAddDTO;
import com.online.teaching.utils.Result;
import com.online.teaching.utils.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @ClassName : AdminCourseController //类名
 * @Description :   //描述
 * @Author : YG  //作者
 * @Date: 2020-11-04 13:22  //时间
 */

/**
 * 未测试
 */
@Api(tags ="管理员管理课程模块，包括排课等")
@RestController
public class AdminCourseController {

    @Autowired
    private AdminCourseService adminCourseService;

    @ApiOperation(value = "管理员获取course列表", notes = "管理员获取course列表")
    @GetMapping("admin/course/getCourseList")
    public Result getCourseList()
    {
        return null;
    }

    @ApiOperation(value = "管理员添加course", notes = "管理员添加course")
    @PostMapping("admin/course/addCourse")
    public Result addCourse(@RequestBody @Valid CourseAddDTO courseAddDTO)
    {
        int i = adminCourseService.addCourse(courseAddDTO);
        return i==1?new Result(true, StatusCode.OK,"课程添加成功"):new Result(true,StatusCode.ERROR,"添加失败");
    }

    @ApiOperation(value = "管理员删除course", notes = "管理员删除course")
    @GetMapping("admin/course/deleteCourse")
    public Result deleteCourse(@RequestParam("courseId") @ApiParam("对应的课程id")Integer courseId)
    {
        int i = adminCourseService.deleteCourse(courseId);
        return i==1?new Result(true, StatusCode.OK,"课程删除成功"):new Result(true,StatusCode.ERROR,"删除失败");
    }

    @ApiOperation(value = "管理员为老师排课", notes = "管理员为老师排课")
    @PostMapping("admin/teaches/addTeaches")
    public Result addTeaches(@RequestBody @Valid TeachesAddDTO teachesAddDTO)
    {
        int i = adminCourseService.addTeaches(teachesAddDTO);
        return i==1?new Result(true, StatusCode.OK,"授课信息添加成功"):new Result(true,StatusCode.ERROR,"授课信息添加失败");
    }

    @ApiOperation(value = "管理员为删除一条排课信息", notes = "管理员删除一条排课信息")
    @PostMapping("admin/teaches/deleteTeaches")
        public Result deleteTeaches(Integer teachesId)
    {
        int i = adminCourseService.deleteTeaches(teachesId);
        return i==1?new Result(true, StatusCode.OK,"授课信息添加成功"):new Result(true,StatusCode.ERROR,"授课信息添加失败");
    }


    @ApiOperation(value = "查询老师开课列表", notes = "查询老师开课列表")
    @PostMapping("admin/teaches/getTeachesList")
    public Result<PageInfo<TeachesGetVO>> getTeachesList(@RequestParam("page")Integer page,@RequestParam("size")Integer size)
    {
        PageInfo<TeachesGetVO> teachesList = adminCourseService.getTeachesList(page, size);
        return new Result(true,StatusCode.OK,"查询成功",teachesList);
    }

    @ApiOperation(value = "管理员为课程添加学生", notes = "管理员为课程添加学生")
    @PostMapping("admin/takes/addTakes")
    public Result addTakes(@RequestBody @Valid TakesAddDTO takesAddDTO)
    {
        int i = adminCourseService.addTakes(takesAddDTO);
        return i==1?new Result(true, StatusCode.OK,"选课信息添加成功"):new Result(true,StatusCode.ERROR,"选课信息添加失败");
    }
}
